package com.aispeech.testcustom;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.aispeech.testcustom.bean.CustomData;
import com.aispeech.testcustom.utils.PreferenceUtil;
import com.aispeech.testcustom.utils.TiLog;
import com.aispeech.testcustom.view.CustomArrayAdapter;
import com.aispeech.testcustom.view.CustomCmdActivity;
import com.aispeech.testcustom.view.HorizontalListView;
import com.aispeech.testcustom.view.MissWakeupActivity;
import com.aispeech.testcustom.view.SettingsActivity;
import com.aispeech.testcustom.view.WakeupActivity;

public class MainActivity extends AppCompatActivity {

    private boolean            alreadyInit;//语音sdk是否已经初始化
    private HorizontalListView mHlvList;
    private CustomData[] mCustomData = new CustomData[]{
            new CustomData(Color.LTGRAY, "自\n定\n义\n指\n令\n接\n口\n测\n试"),
            new CustomData(Color.WHITE, "唤\n醒\n接\n口\n测\n试"),
            new CustomData(Color.LTGRAY, "误\n唤\n醒\n测\n试"),
            new CustomData(Color.WHITE, "设\n置")
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //拿上一次的记录,确保重启后生效
        alreadyInit = PreferenceUtil.SettingPreference.isInitInApplication(this);

        mHlvList = (HorizontalListView) findViewById(R.id.hrz_lv_function);
        CustomArrayAdapter adapter = new CustomArrayAdapter(this, mCustomData);
        mHlvList.setAdapter(adapter);
        mHlvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TiLog.d("alreadyinit : " + alreadyInit + " i:" + i);
                if (!alreadyInit && i != 2 && i != 3) {

                    Toast.makeText(getBaseContext(), "语音sdk还未初始化!!!", Toast.LENGTH_SHORT).show();
                    return;
                }
                switch (i) {
                    case 0:
                        //自定义接口测试
                        startActivity(new Intent(MainActivity.this, CustomCmdActivity.class));
                        break;
                    case 1:
                        //唤醒接口测试
                        startActivity(new Intent(MainActivity.this, WakeupActivity.class));
                        break;
                    case 2:
                        //误唤醒测试
                        startActivity(new Intent(MainActivity.this, MissWakeupActivity.class));
                        break;
                    case 3:
                        //设置
                        startActivity(new Intent(MainActivity.this, SettingsActivity.class));
                        break;
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        TiLog.d("mainActivity destroy! system.exit(-1)");
        System.exit(-1);
    }
}
